﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using PlayerTest.Player.Data;
using PlayerTest.Player.Event;

namespace PlayerTest.CustomControls
{
    /// <summary>
    /// ScriptItem.xaml에 대한 상호 작용 논리
    /// </summary>
    public partial class ScriptItem : UserControl
    {
        private int id;
        private SMIContent smi;

        #region Event

        public event ScriptItemEventHandler eventHandler;
        /// <summary>
        /// Player에게 이벤트 전송
        /// </summary>
        /// <param name="arg"></param>
        private void SendEvent(ScriptItemEventArgs arg)
        {
            // 연결된 모든 함수에 이벤트 전송
            ScriptItemEventHandler handler = eventHandler;
            if (handler != null) handler(this, arg);
        }
        #endregion

        public int ID
        {
            get { return id; }
            set { id = value; }
        }
        public string Text
        {
            get { return text.Text; }
            set { text.Text = value; }
        }
        public SMIContent SMI
        {
            get { return smi; }
            set {
                smi = value;
                text.Text = smi.Text;
            }
        }

        public ScriptItem()
        {
            InitializeComponent();
            id = 0;
        }

        private void ScrapSentenceButton_Click(object sender, RoutedEventArgs e)
        {
            ScrapSentenceButton.Visibility = System.Windows.Visibility.Hidden;
            ScrapSentenceButton_On.Visibility = System.Windows.Visibility.Visible;
            //MessageBox.Show(string.Format("[{0}] : {1}", smi.Time, smi.Text));

            ScriptItemEventArgs arg = new ScriptItemEventArgs(ScriptItemEventArgs.eventtype.SENTENCE);
            arg.Message = smi.Text;
            arg.Position = smi.Time;
            SendEvent(arg);
        }

        private void ScrapWordButton_Click(object sender, RoutedEventArgs e)
        {
            string word = text.SelectedText;
            MessageBox.Show(string.Format("{0}", word));
            /*
            ScriptItemEventArgs arg = new ScriptItemEventArgs(ScriptItemEventArgs.eventtype.WORD);
            arg.Message = word;
            SendEvent(arg);*/
        }
    }
}
